<template>
	<view class="message" v-if="contractStatus.length">
		<!-- <view class="flex-c tabs">
			  <u-tabs
				:list="list2"
				lineWidth="80"
				:itemStyle="{ padding: '0 100rpx', height: '88rpx' }"
				lineColor="#138E57"
			  ></u-tabs>
			</view> -->
			<view class="message-list">
				<!-- <view v-for="(item,index) in list" :key="index"> -->
					<!-- <view class="flex-c item-time">2023-02-11</view> -->
					<view v-for="(item,index) in list" :key="index" class="item-info" @click="
						$route({
						  url: '/pages/message/detail',
						  params: {
							id: item.id,
							memo: item.memo
						  },
						})
					  ">
						<view>
							{{item.name}}
							<u-badge v-if="item.memo == '0'" absolute :isDot="true" type="error" :offset="['14rpx', '-30rpx']"></u-badge>
						</view>
						<view class="l-ellipsis-2">
							{{item.content}}
						</view>
					</view>
				<!-- </view> -->
			</view>
			<uni-load-more :status="status_load"></uni-load-more>
		<!-- <Tabbar index="3"></Tabbar> -->
		
	</view>
	<view class="qinayue" v-else>
		当前账号不是签约人，暂不开放
	</view>
</template>

<script>
	import Tabbar from "@/components/Tabbar/index.vue";

	import {
		messageList,
		signDetails,
		InSignUnitList
	} from "@/api";
	export default {
		components: {
			Tabbar,
		},
		data() {
			return {
				contractStatus:'',//是否签约
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				list:[],
				status_load: 'more',
				// memo 1已读  0未读
				queryParams:{
					recipientId:'',
					pageNum: 1,
					pageSize: 10,
				},
			
			};
		},	

		onShow() {
			this.list = []
			this.$store.dispatch("userInfo");
			this.InSignUnitList()
		},
		methods: {
			InSignUnitList(){
				InSignUnitList().then(res => {
					this.contractStatus = res.data
					if(res.data.length){
						this.signDetails(res.data[0].deptId)
					}
				})
			},
			// 签约信息
			signDetails(id) {
				let deptId;
				// console.log("uni.getStorageSync('deptId')",uni.getStorageSync('deptId'));
				if(uni.getStorageSync('deptId')){
					deptId = uni.getStorageSync('deptId')
				}else{
					deptId = id
					uni.setStorageSync('deptId', deptId);
				}
				signDetails({
					deptId:deptId
				}).then(res => {
					this.queryParams.recipientId = res.data.id
					if(res.data.id){
						this.messageList()
					}
					
				})
			},
			messageList(){
				// let userInfo = wx.getStorageSync('userInfo')
				// this.queryParams.recipientId = userInfo.userId
				messageList({
					...this.queryParams
				}).then(res => {
					uni.hideLoading()
					let data = res.data.records
					if (data) {
						this.list = this.list.concat(data)
					}
					if (this.queryParams.pageSize == data.length) {
						this.queryParams.pageNum += 1;
						this.status_load = 'more'
					} else {
						this.status_load = 'noMore'
					}
				})
			},
			
		}
		
	};
</script>

<style lang="less" scoped>
	.qinayue{
		width: 100vw;
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.message {
		.tabs {
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			background: #fff;
			z-index: 99;
		}

		.message-list {
			padding: 30rpx;
		}

		.item-time {
			margin-bottom: 20rpx;
		}

		.item-info {
			margin-bottom: 30px;
			padding: 30rpx;
			background: #fff;
			border-radius: 12rpx;

			view:nth-child(1) {
				font-size: 30rpx;
				color: #000000;
				margin-bottom: 10rpx;
				position: relative;
				display: inline-block;
			}

			view:nth-child(2) {
				font-size: 28rpx;
				color: #666668;
			}
		}
	}
</style>